package top.healthylife.gateway.platform.mysql.api.check;

import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import top.healthylife.basics.utils.exception.BusinessException;
import top.healthylife.gateway.core.config.BaseConfig;
import top.healthylife.gateway.core.service.CheckSecretService;
import top.healthylife.gateway.platform.mysql.api.config.SystemConfig;

import java.util.Map;

/**
 * @author : GaoZeXi
 * @date 2021/3/19 14:48
 */
@Service
@AllArgsConstructor
public class CheckSecretServiceImpl implements CheckSecretService {
    DynamicDataSourceProperties dynamicDataSourceProperties;

    @Override
    public void checkSecret(BaseConfig baseConfig) {
        SystemConfig innerBlackConfig = (SystemConfig) baseConfig;
        Map<String, DataSourceProperty> datasource = dynamicDataSourceProperties.getDatasource();
        if (!datasource.keySet().contains(innerBlackConfig.getName())) {
            throw new BusinessException("未检测到对应的数据源配置");
        }
    }
}
